/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 最终版学生成绩管理系统;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class IndexOfClass extends IndexOrManage implements ActionListener{

	String[] classes={"","1","2","3","4","5","6"};
	JComboBox clas=new JComboBox(classes);
	JLabel la=new JLabel("选择查询班别");
	
public IndexOfClass(){
		
		super();
		p1.add(la);
		p1.add(clas);
		//注册监听
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
		
		pack();
		setVisible(true);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO 自动生成的方法存根
		if(e.getActionCommand()=="显示"){
			text.setText("");
			
			if(clas.getSelectedItem().equals("")){
				JOptionPane.showMessageDialog(null, "找不到该班别", "Message",
						JOptionPane.INFORMATION_MESSAGE);
			}
			else
			try{
				Connection con=DataBaseCreate.getConnection();
				Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
				//按班别查找数据库数据
				ResultSet rs=sql.executeQuery("select * from student where Class like '%"+clas.getSelectedItem()+"%'");
				text.append("全校"+clas.getSelectedItem()+"班学生信息:\r\n");
				text.append("学号                姓名                生日                专业                         年级                班别                语文                        英语                        数学                        总分\r\n");
				while(rs.next()){
					text.append(rs.getString("Num")+"           "+rs.getString("Name")+"           "+rs.getString("Birth")+"           "+rs.getString("Major")
							+"              "+rs.getString("Grade")+"                      "+rs.getString("Class")+
							"                      "+rs.getFloat("Chinese")+"                      "+rs.getFloat("English")
							+"                      "+rs.getFloat("Maths")+"                      "+rs.getFloat("Total")+"\r\n");
				}
				
				
			}catch(java.lang.ClassNotFoundException err){
				JOptionPane.showMessageDialog(null, err.getMessage(), "ClassNotFoundException:",
						JOptionPane.INFORMATION_MESSAGE);
				}catch (SQLException ex){
					JOptionPane.showMessageDialog(null, ex.getMessage(), "SQLException: ", JOptionPane.INFORMATION_MESSAGE);
				}
		}
		else if(e.getActionCommand()=="取消"){
			setVisible(false);
		}
		else if(e.getActionCommand()=="保存"){
			TxtSave save=new TxtSave(text.getText(),"全体"+(String) clas.getSelectedItem());
		}
	}
}
